package project.dade.cn.bst.utils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by vain zhou on 2015/9/22.
 */
public class SharePreferenceUtil {
    private static SharedPreferences sp;
    private SharedPreferences.Editor editor;
    /**
     * 用户是否第一次打开
     */
    public static final String SP_NAME = "config";
    /**
     * 用户是否登录
     */
    private static final String ISLOGIN = "isLogin";
    /**
     * 用户ID
     */
    private static final String USER_ID = "userid";
    /**
     * 洗衣商品ID
     */
    private static final String USER_mobile = "usermoblie";
    /**
     * 洗衣ID
     */
    private static final String ID_Cloth = "clothid";
    /**
     * 洗车ID
     */
    private static final String ID_Car = "carid";

    @SuppressLint("CommitPrefEdits")
    public SharePreferenceUtil(Context context, String file) {
        sp = context.getSharedPreferences(file, Context.MODE_PRIVATE);
        editor = sp.edit();
    }
    /**
     * 获取用户是否第一次打开
     *
     * @return boolean true 登录 , false 未登录（默认）
     * @throws
     * @Title: isLogin
     * @Description: 判断用户是否登录
     */
    public static void saveBoolean(Context ct, String key, boolean value) {
        if (sp == null){
            sp = ct.getSharedPreferences(SP_NAME, 0);
        }

        sp.edit().putBoolean(key, value).commit();
    }
    /**
     * 获取用户是否第一次打开
     *
     * @return boolean true 登录 , false 未登录（默认）
     * @throws
     * @Title: isLogin
     * @Description: 判断用户是否登录
     */
    public static boolean getBoolean(Context ct, String key, boolean defValue) {
        if (sp == null){
            sp = ct.getSharedPreferences(SP_NAME, 0);
        }
        return sp.getBoolean(key, defValue);

    }
    /**
     * 获取用户是否第一次打开
     *
     * @return boolean true 登录 , false 未登录（默认）
     * @throws
     * @Title: isLogin
     * @Description: 判断用户是否登录
     */
    public boolean isLogin() {
        return sp.getBoolean(ISLOGIN, false);
    }

    /**
     * 设置用户是否登录
     *
     * @param islogin true 登录 , false 未登录
     * @return void
     * @throws
     * @Title: setLogin
     * @Description:
     */
    public void setLogin(boolean islogin) {
        editor.putBoolean(ISLOGIN, islogin);
        editor.commit();
    }
    /**
     * 设置用户ID
     *
     * @param id 用户ID
     * @return void 无
     * @throws
     * @Title: setUserID
     * @Description: 设置用户ID
     */
    public void setUserID(long id) {
        editor.putLong(USER_ID, id);
        editor.commit();
    }

    /**
     * 获取用户ID
     *
     * @param
     * @return String 返回用户ID
     * @throws
     * @Title: getUserID
     * @Description: 获取用户ID
     */
    public Long getUserID() {
        return sp.getLong(USER_ID, -1);
    }
    /**
     * 获取用户登录手机号码
     *
     * @param
     * @return String 返回用户手机号码
     * @throws
     * @Title: getUserID
     * @Description: 获取用户手机号码
     */
    public  String getUSER_mobile() {
        return sp.getString(USER_mobile,"");
    }
    public void setUSER_mobile(String mobile) {
        editor.putString(USER_mobile, mobile);
        editor.commit();
    }
    /**
     * 洗衣商品ID
     *
     * @param id 洗衣ID
     * @return void 无
     * @throws
     * @Title: setCloth
     * @Description: 设置洗衣ID
     */
    public void setID_Cloth(String id) {
        editor.putString(ID_Cloth, id);
        editor.commit();
    }

    /**
     * 获取洗衣ID
     *
     * @param
     * @return String 返回洗衣ID
     * @throws
     * @Title: getUserID
     * @Description: 获取洗衣ID
     */
    public String  getID_Cloth() {
        return sp.getString(ID_Cloth, "");
    }
    /**
     * 获取洗车ID
     *
     * @param
     * @return String 返回洗衣ID
     * @throws
     * @Title: getUserID
     * @Description: 获取洗车ID
     */
    public String  getID_Car() {
        return sp.getString(ID_Car, "");
    }
    /**
     * 洗衣商品ID
     *
     * @param id 洗车ID
     * @return void 无
     * @throws
     * @Title: setCloth
     * @Description: 设置洗车ID
     */
    public void setID_Car(String id) {
        editor.putString(ID_Car, id);
        editor.commit();
    }







}
